﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ilanver.Data.NHibernate.Abstraction;
using NHibernate;

namespace ilanver.Data.NHibernate
{
    public class SimpleSessionStorage : ISessionStorage
    {
        private Dictionary<string, ISession> storage = new Dictionary<string, ISession>();

        public global::NHibernate.ISession GetSessionForKey(string factoryKey)
        {
            ISession session;

            if (!storage.TryGetValue(factoryKey, out session))
                return null;

            return session;
        }

        public void SetSessionForKey(string factoryKey, global::NHibernate.ISession session)
        {
            storage[factoryKey] = session;
        }

        public IEnumerable<global::NHibernate.ISession> GetAllSessions()
        {
            return storage.Values;
        }
    }
}
